<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <!--IE Compatibility modes-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--Mobile first-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>403</title>

    <meta name="description" content="Free Admin Template Based On Twitter Bootstrap 3.x">
    <meta name="author" content="">

    <meta name="msapplication-TileColor" content="#5bc0de"/>
    <meta name="msapplication-TileImage" content="assets/img/metis-tile.png"/>

    <!-- Bootstrap -->
    <link href="//cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- Font Awesome -->
    <!--<link rel="stylesheet" href="assets/lib/font-awesome/css/font-awesome.min.css">-->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="/assets/lib/bootstrap-table/bootstrap-table.min.css">
    <link rel="stylesheet" href="/assets/lib/bootstrap-switch/css/bootstrap3/bootstrap-switch.min.css">
    <!-- Metis core stylesheet -->
    <link rel="stylesheet" href="/assets/css/main.css">
    <!-- animate.css stylesheet -->
    <link rel="stylesheet" href="/assets/lib/animate.css/animate.css"/>
    <link rel="stylesheet" href="/assets/lib/select2/css/select2.min.css"/>
    <link rel="stylesheet" href="/assets/lib/bootstrap-validator/css/bootstrapValidator.min.css"/>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="//oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="//oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <style>
        .text_info {
            border: 0px;
        }
    </style>


    <![endif]-->
</head>

<body>
<div class="bg-dark dk" id="wrap" style="height:50px;">
    <header class="head">
        <div class="">
            <ol class="breadcrumb" style="background-color: #3a3a3a">
                <li><a href="#"> <i class="fa fa-home">系统管理</i></a></li>
                <li class="active">平台账户调整</li>
            </ol>
        </div>
        <!-- /.main-bar -->
    </header>
</div>
<div class="container bg-info" style="width:100%;">

    <div class="row " >

        <div class="">
            <h3 class="page-header">调整</h3>
            <form class="form-horizontal" role="form" id="fission_form">
                <div class="form-group">
                    <label for="bal1" class="col-sm-4 control-label" id="label1">
                    </label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" id="bal1" name="bal1" onKeyUp="amount(this)" onBlur="overFormat(this)"  placeholder="调配金额（2位小数）">
                    </div>
                    <div class="col-sm-4">
                        <button type="button" id="transfer_button1" class="btn btn-warning">调整转换</button>
                    </div>
                </div>
                <div class="form-group">
                    <label for="bal2" class="col-sm-4 control-label" id="label2">
                    </label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" id="bal2" name="bal2" onKeyUp="amount(this)" onBlur="overFormat(this)"  placeholder="调配金额（2位小数）">
                    </div>
                    <div class="col-sm-4">
                        <button type="button" id="transfer_button2" class="btn btn-warning">调整转换</button>
                    </div>
                </div>
                <div class="form-group">
                    <label for="bal3" class="col-sm-4 control-label" id="label3">
                    </label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" id="bal3" name="bal3"onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
                               onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" placeholder="增加/减少数量（整数）">
                    </div>
                    <div class="col-sm-4">
                        <button type="button" id="transfer_button3" class="btn btn-warning">增加</button>
                        <button type="button" id="transfer_button4" class="btn btn-warning">减少</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

</div>
<!--jQuery -->
<script src="/assets/lib/jquery/jquery.min.js"></script>
<!--Bootstrap -->
<script src="/assets/lib/bootstrap/js/bootstrap.min.js"></script>
<script src="/assets/lib/bootstrap-table/bootstrap-table.min.js"></script>
<script src="/assets/lib/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="/assets/lib/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<script src="/assets/lib/select2/js/select2.min.js"></script>
<script src="/assets/lib/bootstrap-validator/js/bootstrapValidator.min.js"></script>
<!-- MetisMenu -->
<script src="/assets/lib/metismenu/metisMenu.js"></script>
<!-- Metis core scripts -->
<script src="/assets/js/core.js"></script>
<script src="/assets/js/utils.js"></script>

<!-- Metis demo scripts -->
<script src="/assets/js/app.js"></script>
<script src="/assets/lib/layer/layer.js"></script>
<script>
    var csrf_token = "${_csrf.token}";
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': csrf_token
        }
    });
    layer.config({
        extend: 'extend/layer.ext.js'
    });

    $.ajax({
        type: "GET",
        dataType: "json",
        url: "/sysm/getPlatform",
        success: function (res) {
            $("#label1").append("公司资金池（"+res.data.companyFundPool+"）==>>市场资金池（"+res.data.marketFundPool+"）");
            $("#label2").append("市场资金池（"+res.data.marketFundPool+"）==>>公司资金池（"+res.data.companyFundPool+"）");
            $("#label3").append("公司MS（"+res.data.companyMsk+"）");
        },
        error: function (xhr, errorType, error) {
            layer.msg("获取失败", {icon: 7});
        }
    });


    $(document).on("click", "#transfer_button1", function (event) {
        var form=serializeFormToObject($("#fission_form"));
        if(form.bal1==""){
            layer.tips('操作失败,请输入调配金额', '#transfer_button1', {
                tips: 1
            });
            return false;
        }
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/sysm/companyToMarket",
            async: false,
            data: form,
            success: function (res) {
                if (res.status != "y") {
                    layer.alert(res.info, {icon: 7});
                    return ;
                } else {
                    layer.msg("调配成功", {icon: 6});
                    location.reload();
                }
            },
            error: function (xhr, errorType, error) {
                layer.alert(res.info, {icon: 7});
                return ;
            }
        });
    });
    $(document).on("click", "#transfer_button2", function (event) {
        var form=serializeFormToObject($("#fission_form"));
        if(form.bal2==""){
            layer.tips('操作失败,请输入调配金额', '#transfer_button2', {
                tips: 1
            });
            return false;
        }
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/sysm/marketToCompany",
            async: false,
            data: form,
            success: function (res) {
                if (res.status != "y") {
                    layer.alert(res.info, {icon: 7});
                    return ;
                } else {
                    layer.msg("调配成功", {icon: 6});
                    location.reload();
                }
            },
            error: function (xhr, errorType, error) {
                layer.alert(res.info, {icon: 7});
                return ;
            }
        });
    });

    $(document).on("click", "#transfer_button3", function (event) {
        var form=serializeFormToObject($("#fission_form"));
        if(form.bal3==""){
            layer.tips('操作失败,请输入要增加的数量', '#transfer_button3', {
                tips: 1
            });
            return false;
        }
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/sysm/companyMsA",
            async: false,
            data: form,
            success: function (res) {
                if (res.status != "y") {
                    layer.alert(res.info, {icon: 7});
                    return ;
                } else {
                    layer.msg("增加成功", {icon: 6});
                    location.reload();
                }
            },
            error: function (xhr, errorType, error) {
                layer.alert(res.info, {icon: 7});
                return ;
            }
        });


    });

    $(document).on("click", "#transfer_button4", function (event) {
        var form=serializeFormToObject($("#fission_form"));
        if(form.bal3==""){
            layer.tips('操作失败,请输入要减少的数量', '#transfer_button4', {
                tips: 1
            });
            return false;
        }
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/sysm/companyMsS",
            async: false,
            data: form,
            success: function (res) {
                if (res.status != "y") {
                    layer.alert(res.info, {icon: 7});
                    return ;
                } else {
                    layer.msg("减少成功", {icon: 6});
                    location.reload();
                }
            },
            error: function (xhr, errorType, error) {
                layer.alert(res.info, {icon: 7});
                return ;
            }
        });


    });


    function amount(th) {
        var regStrs = [
            ['^0(\\d+)$', '$1'], //禁止录入整数部分两位以上，但首位为0
            ['[^\\d\\.]+$', ''], //禁止录入任何非数字和点
            ['\\.(\\d?)\\.+', '.$1'], //禁止录入两个以上的点
            ['^(\\d+\\.\\d{2}).+', '$1'] //禁止录入小数点后两位以上
        ];
        for (var i = 0; i < regStrs.length; i++) {
            var reg = new RegExp(regStrs[i][0]);
            th.value = th.value.replace(reg, regStrs[i][1]);
        }
    }

    function overFormat(th) {
        var v = th.value;
        if (v === '') {
            v = '0.00';
        } else if (v === '0') {
            v = '0.00';
        } else if (v === '0.') {
            v = '0.00';
        } else if (/^0+\d+\.?\d*.*$/.test(v)) {
            v = v.replace(/^0+(\d+\.?\d*).*$/, '$1');
            v = inp.getRightPriceFormat(v).val;
        } else if (/^0\.\d$/.test(v)) {
            v = v + '0';
        } else if (!/^\d+\.\d{2}$/.test(v)) {
            if (/^\d+\.\d{2}.+/.test(v)) {
                v = v.replace(/^(\d+\.\d{2}).*$/, '$1');
            } else if (/^\d+$/.test(v)) {
                v = v + '.00';
            } else if (/^\d+\.$/.test(v)) {
                v = v + '00';
            } else if (/^\d+\.\d$/.test(v)) {
                v = v + '0';
            } else if (/^[^\d]+\d+\.?\d*$/.test(v)) {
                v = v.replace(/^[^\d]+(\d+\.?\d*)$/, '$1');
            } else if (/\d+/.test(v)) {
                v = v.replace(/^[^\d]*(\d+\.?\d*).*$/, '$1');
                ty = false;
            } else if (/^0+\d+\.?\d*$/.test(v)) {
                v = v.replace(/^0+(\d+\.?\d*)$/, '$1');
                ty = false;
            } else {
                v = '0.00';
            }
        }
        th.value = v;
    }
</script>
</body>

</html>
